/**
 * @author wn
 * @date 2022/08/17 14:41:56
 * @description: 个人中心 支付 订单 相关API
 */

import request from '@/utils/request'

/**
 * 结算页面-生成订单-根据购物车选中商品
 * @returns
 */

export const findCheckOutInfo = () => request('/member/order/pre')

/**
 * 添加收货地址
 * @param {Object} form - 参考接口文档
 */

export const addAddress = form => request('/member/address', form, 'POST')

/**
 * 修改收货地址
 * @param {Object} form - 参考接口文档
 */

export const editAddress = form =>
	request(`/member/address/${form.id}`, form, 'PUT')

/**
 * 获取收货地址列表
 * @param {Object}
 */

export const findAddress = () => request('/member/address')

/**
 * 删除收货地址
 * @param {Object} id 收货地址id
 */
export const deleteAddress = id => request(`/member/address/${id}`, 'DELETE')

/**
 * 结算页面-提交订单
 * @param {Object} params - 参考接口文档
 * @returns
 */

export const submitOrder = params => request('/member/order', params, 'POST')

/**
 * 获取订单详细
 * @param {String} orderId - 订单ID--主要是应付总额 和 倒计时时间
 * @returns
 */

export const findOrderDetail = orderId => request(`/member/order/${orderId}`)

/**
 * 获取订单列表
 * @param {String} page - 页码
 * @param {String} pageSize - 每页条数
 * @param {String} orderState - 订单状态，1为待付款、2为待发货、
 * 3为待收货、4为待评价、5为已完成、6为已取消，未传该参数或0为全部
 * @returns
 */

export const findOrderList = ({ page = 1, pageSize = 10, orderState = 0 }) =>
	request('/member/order', { page, pageSize, orderState })

/**
 * 取消订单
 * @param {String} orderId - 订单ID
 * @param {String} cancelReason - 取消原因
 * @returns
 */

export const cancelOrder = (orderId, cancelReason) => {
	return request(`/member/order/${orderId}/cancel`, { cancelReason }, 'PUT')
}

/**
 * 删除订单
 * @param {Array} orderIds - 订单ID 数组
 * @returns
 */

export const deleteOrder = orderIds =>
	request('/member/order', { ids: orderIds }, 'DELETE')

/**
 * 确认收货
 * @param {String} orderId - 订单ID
 * @returns
 */

export const confirmOrder = orderId =>
	request(`/member/order/${orderId}/receipt`, undefined, 'PUT')

/**
 * 查询物流
 * @param {String} orderId - 订单ID
 * @returns
 */

export const logisticsOrder = orderId =>
	request(`/member/order/${orderId}/logistics`)

/**
 * 结算页面-生成订单-根据订单中商品-再次购买
 * @returns
 */

export const repurchaseOrder = orderId =>
	request(`/member/order/repurchase/${orderId}`)
